package top.itaso.app.ui.settings

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import top.itaso.app.R
import top.itaso.lib.common.StorageVolumeUtils
import top.itaso.lib.widget.tpv.TpvCommonItemView

/**
 * @Description:
 * @Author itsdf07
 * @E-Mail 923255742@qq.com
 * @Gitee https://gitee.com/itsdf07
 * @Date 2023/11/28
 */
class ShowInfoFragment : Fragment() {
    private lateinit var mViewModel: SettingsViewModel
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mViewModel = ViewModelProvider(this).get(SettingsViewModel::class.java)
        val rootView = inflater.inflate(R.layout.fragment_showinfo, container, false)
        initView(rootView)
        return rootView
    }

    private fun initView(rootView: View) {
        val tvShowDir: TextView = rootView.findViewById(R.id.tv_show_dir)
        tvShowDir.text = StorageVolumeUtils.getAppPrivateDir(context)
        tvShowDir.setOnLongClickListener { v ->
            val clipboardManager: ClipboardManager =
                context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
            val clipData: ClipData = ClipData.newPlainText("content", (v as TextView).text)
            clipboardManager.setPrimaryClip(clipData)
            Toast.makeText(context, "复制成功", Toast.LENGTH_SHORT).show()
            true
        }
    }
}